import axios from 'axios';
import {getToken} from "@/api/getToken";
import { Toast } from 'vant'
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
axios.defaults.crossDomain = true;
const request = axios.create({
  baseURL : 'http://192.168.1.4:3000'
});
request.interceptors.request.use((config) => {
  if (getToken('token')){
    config.headers['token'] = getToken('token');
    config.headers['Content-type'] = 'application/json'
  }
  return config
},(err) => {
  return Promise.reject(err)
});
request.interceptors.response.use((response) => {
  let { status , data} = response;
  console.log('response', response)
  if (status != 200) {
    console.log(data.msg)
  }
  if (data.status !== 200){
    Toast({
      message: data.msg,
    });
  }
  return response
},(error) => {
  return Promise.reject(error)
});
export default request
